package com.lightdz.tshirtdz.bll;

import com.lightdz.tshirtdz.model.PageInfo;
import com.lightdz.tshirtdz.model.api.ApiFrontPage;
import com.lightdz.tshirtdz.model.api.ApiProduct;
import com.lightdz.tshirtdz.model.api.ApiResponse;

import com.lightdz.tshirtdz.utils.LogHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

/**
 * @ Description：${description}
 * @ Author     ：zbl
 * @ Date       ：Created in 16:54 09/08/2018
 * @ Modified By：
 */
@Repository
public class FrontPageBll {

    @Autowired
    ProductBll productBll;

    /**
     * 拿到首页的所有信息
     * @param pageInfo
     * @return
     */
    public ApiResponse<ApiFrontPage> getFrontPage(PageInfo pageInfo){

        ApiResponse<ApiFrontPage> apiResponse=ApiResponse.getNoResponse();

        ApiFrontPage frontPage= null;
        try {
            frontPage = new ApiFrontPage();

            ApiResponse<List<ApiProduct>> productList = productBll.getProductList(null,pageInfo);
            //TODO 首页的banner图片待确认
            frontPage.setBannerPicUrl(new ArrayList<>());
            if(productList!=null){
                frontPage.setProductList(productList.getData());
            }

            apiResponse=new ApiResponse<>(frontPage);
        } catch (Exception e) {
            e.printStackTrace();
            LogHelper.error("FrontPageBll.getFrontPage",e);
        }

        return apiResponse;
    }
}
